//
// Created by Administrator on 2024/1/31.
//

#include <vector>
#include <iostream>
#include <set>
using namespace std;

class Solution
{
public:
    bool checkValid(vector<vector<int>>& matrix)
    {
        // 检查是不是每行每列都包含了所有的1到n的数字
        set<int>s;
        auto n = matrix.size();
        // 检查每行
        for (int i = 0; i < n; ++i)
        {
            for (int j = 0; j < n; ++j)
            {
                s.insert(matrix[i][j]);
            }
            if (s.size()!= n) return false;
            s.clear();
        }
        // 检查每列
        for (int i = 0; i < n; ++i)
        {
            for (int j = 0; j < n; ++j)
            {
                s.insert(matrix[j][i]);
            }
            if (s.size()!= n) return false;
            s.clear();
        }
        return  true;
    }
};

int main()
{
    vector<vector<int>> matrix{{1, 2, 2}, {2, 3, 1}, {3, 1, 2}};
    Solution s;
    cout << s.checkValid(matrix) << endl;
    return 0;
}
